import java.util.Random;
import java.util.Scanner;

public class Method {
    public static void main(String[] args){
        //猜数字游戏：
        Random random = new Random();
        Scanner scanner = new Scanner(System.in);
        int toGuess = random.nextInt(100);
        System.out.println("toGuess:"+toGuess);
        while(true){
            System.out.println("请输入要输入的数字：");
            int num = scanner.nextInt();
            if(num < toGuess){
                System.out.println("低了");
            } else if (num > toGuess) {
                System.out.println("高了");
            }else {
                System.out.println("猜对了");
                break;
            }
        }

        //判定一个数是否是素数：
        for(int k = 1;k < 100 ;k++){
            int i = 2;
            for(;i <= Math.sqrt(k) ;i++){
                if( k % i == 0){
                    break;
                }
            }
            if(i > Math.sqrt(k)){
                System.out.println(k);
            }
        }
        int ret = gcdByEuclidean(10,20);
        System.out.println("10和20的最大公约数为："+ret);
        int num1 = NarcissisticNumbers(153);
        int num2 = numberOfOne(00001111);
        System.out.println(num2);
    }
    //求两个正数的最大公约数：
    public static int gcdByEuclidean(int a,int b){
        while (b != 0){
            int temp = b;
            b = a % b;
            a = temp;
        }
        return a;
    }
    //判断一个数是否是水仙花数：
    public static int NarcissisticNumbers(int num){
        int ge,shi,bai,ret = 0;
        if(num > 99){
             ge = num % 10;
             shi = num / 10 % 10;
             bai = num / 100 % 10;
             ret = ge * ge * ge + shi * shi * shi + bai * bai * bai;
        }
        if(num == ret){
            System.out.println(num);
        }
        return num;
    }
    //写一个函数返回参数二进制中1的个数：
    public static int numberOfOne(int num){
        int count = 0;
        while(num != 0){
            num = num & (num - 1);
            count ++;
        }
        return count;
    }
}
